package classes;

import java.util.Random;

public class P3thread extends Thread {
	int ndort;
	int nthread;
	int pix[][];
	int myid;
	public static final int CIRCLE_DIAMETER = 100;
	public static final int X_CIRCLE = 50;
	public static final int Y_CIRCLE = 50;
	
	
	public static void main(String args[]) throws Throwable  {
			 
		
	 }
	 public P3thread(int numdort,int numthread,int pix[][],int id){
		 ndort = numdort;
		 nthread = numthread;
		 this.pix = pix;
		 myid = id;
		 
	 }
	 public void run (){
		 	
		 
	    	int x = 0;
	    	int y = 0;
	    	int M = 0;
	    	int endloop = 0;
	    	
	    	
		 try{
			 
			 Random randomGenerator = new Random();
			 
			 if (myid == nthread) {
				 endloop = ndort;
			 }else {
				 endloop = (myid)*(ndort/nthread);
			 }
			 
			
			 
	         for (int idx =(myid-1)*(ndort/nthread) ; idx < endloop ; idx++){
	            
	        	 int aStart = X_CIRCLE;
	        	 int aEnd = X_CIRCLE + CIRCLE_DIAMETER;
	        	 if ( aStart > aEnd ) {
	        	      throw new IllegalArgumentException("Start cannot exceed End.");
	        	 }
	        	    //get the range, casting to long to avoid overflow problems
	        	long range = (long)aEnd - (long)aStart + 1;
	        	    // compute a fraction of the range, 0 <= frac < range
	        	long fraction = (long)(range * randomGenerator.nextDouble());
	        	x =  (int)(fraction + aStart); 
	        	fraction = (long)(range * randomGenerator.nextDouble());
	        	y =  (int)(fraction + aStart); 
	        	 
	            pix[idx][0] = x;
	            pix[idx][1] = y;
	          
	            if ((((x - 100)*(x - 100)) + ((y-100)*(y-100))) < (CIRCLE_DIAMETER/2)*(CIRCLE_DIAMETER/2)) {
	        		M++;
	        		pix[idx][2] = 1;
	        	}
	            else{
	            	  pix[idx][2] = 0;
	            }
	            
	         }
	         part3.setDartInCircle(M);
		 }catch (Throwable t){} 
		 

}
}
